package com.wicket.okrbff.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrbff.biz.service.AchievementDockService;
import com.wicket.okrbff.biz.service.dto.req.*;
import com.wicket.okrbff.biz.service.dto.res.*;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.util.CommonFunctionHelper;
import com.wicket.okrbff.common.util.RedisUtil;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrframework.integration.FwBaseInductionRecordClient;
import com.wicket.okrframework.integration.dto.QueryStaffInductionRecordListComRespDto;
import com.wicket.okrframework.integration.dto.QueryStaffInductionRecordListComReqDto;
import com.wicket.okrapp.integration.FwAppAchievementDockClient;
import com.wicket.okrapp.integration.dto.BatchQueryAchievementDockByCreateInductionIdComRespDto;
import com.wicket.okrapp.integration.dto.BatchQueryAchievementDockByCreateInductionIdComReqDto;
import com.wicket.okrbff.biz.service.dto.common.BffAchievementDockingDto;
import java.util.stream.Collectors;
import com.wicket.okrbff.common.exception.Assert;
import com.wicket.okrapp.integration.FwAppAchievementClient;
import com.wicket.okrcomponent.integration.FwCompInterfaceModeClient;
import com.wicket.okrapp.integration.dto.QueryAchievementDockingListComRespDto;
import com.wicket.okrapp.integration.dto.QueryAchievementDockingListComReqDto;
import com.wicket.okrcomponent.integration.dto.ImplementTwoDataRemovalExistsComRespDto;
import com.wicket.okrcomponent.integration.dto.ImplementTwoDataRemovalExistsComReqDto;
import com.wicket.okrcalc.integration.dto.DataSetsListOneDto;
import com.wicket.okrcomponent.integration.dto.DataSetsListTwoDto;
import com.wicket.okrapp.integration.dto.BatchQueryAchievementInfoComRespDto;
import com.wicket.okrapp.integration.dto.BatchQueryAchievementInfoComReqDto;
import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrapp.integration.dto.BatchQueryAchievementByCreateInductionIdComRespDto;
import com.wicket.okrapp.integration.dto.BatchQueryAchievementByCreateInductionIdComReqDto;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class AchievementDockServiceImpl implements AchievementDockService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  FwBaseInductionRecordClient fwBaseInductionRecordClient;

@Resource
  FwAppAchievementDockClient fwAppAchievementDockClient;
@Resource
  FwAppAchievementClient fwAppAchievementClient;

@Resource
  FwCompInterfaceModeClient fwCompInterfaceModeClient;
/**
   * B3按创建人查询可对接成果列表	[9979]
   * gen by moon at 8/15/2024, 10:58:56 PM
   */
    @Trace(operationName = "B3按创建人查询可对接成果列表	")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffBatchQueryAchievementDockByCreateInductionIdRespDto batchQueryAchievementDockByCreateInductionId(BffBatchQueryAchievementDockByCreateInductionIdReqDto reqDto){
      
       
       BatchQueryAchievementInfoComRespDto batchQueryAchievementInfoComRespDto_1 =null;
//virtualUsage D1查询员工就职记录列表(公共)  72174
     QueryStaffInductionRecordListComRespDto queryStaffInductionRecordListComRespDto = null;
    QueryStaffInductionRecordListComReqDto queryStaffInductionRecordListComReqDto=new QueryStaffInductionRecordListComReqDto();
  queryStaffInductionRecordListComReqDto.setOriginalRoleMemberId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecOriginalRoleMemberId());//CURRENT_ORIGINAL_ROLE_MEMBERID//sourceId:1939002_1_72174
  
    /*D1查询员工就职记录列表(公共)[9978]   */
    Assert.isNull(queryStaffInductionRecordListComReqDto.getOriginalRoleMemberId(),"B3按创建人查询可对接成果列表	-D1查询员工就职记录列表(公共)-身份人员ID不能为空",false);
      queryStaffInductionRecordListComRespDto = fwBaseInductionRecordClient.queryStaffInductionRecordListCom(queryStaffInductionRecordListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
//virtualUsage D3批量查询成果by创建人(公共)  72186
      BatchQueryAchievementByCreateInductionIdComRespDto batchQueryAchievementByCreateInductionIdComRespDto = null;
    if(queryStaffInductionRecordListComRespDto !=null){
          BatchQueryAchievementByCreateInductionIdComReqDto batchQueryAchievementByCreateInductionIdComReqDto=new BatchQueryAchievementByCreateInductionIdComReqDto();
  batchQueryAchievementByCreateInductionIdComReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:1970975_1_72186
  if(queryStaffInductionRecordListComRespDto!=null){
      batchQueryAchievementByCreateInductionIdComReqDto.setAchievementList(queryStaffInductionRecordListComRespDto.getOrgInductionRecordList());//list-field-assign//sourceId:1970974_1_72186
    }
  
    /*D3批量查询成果by创建人(公共)[10098]   */
    Assert.isNull(batchQueryAchievementByCreateInductionIdComReqDto.getSpaceId(),"B3按创建人查询可对接成果列表	-D3批量查询成果by创建人(公共)-创建于空间ID不能为空",false);
      batchQueryAchievementByCreateInductionIdComRespDto = fwAppAchievementClient.batchQueryAchievementByCreateInductionIdCom(batchQueryAchievementByCreateInductionIdComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      

           }
//virtualUsage D3查询对接成果关系列表(公共)  72176
      QueryAchievementDockingListComRespDto queryAchievementDockingListComRespDto = null;
    QueryAchievementDockingListComReqDto queryAchievementDockingListComReqDto=new QueryAchievementDockingListComReqDto();
  queryAchievementDockingListComReqDto.setIsArchive("FALSE");//sourceId:1970917_1_72176
queryAchievementDockingListComReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:1970918_1_72176
if(reqDto!=null){
      queryAchievementDockingListComReqDto.setTargetCycleContentId(reqDto.getTargetCycleContentId());//SimpleFieldAssign//sourceId:1970916_1_72176
    }

    /*D3查询对接成果关系列表(公共)[9146]   */
    Assert.isNull(queryAchievementDockingListComReqDto.getTargetCycleContentId(),"B3按创建人查询可对接成果列表	-D3查询对接成果关系列表(公共)-归属目标内容ID不能为空",false);
Assert.isNull(queryAchievementDockingListComReqDto.getIsArchive(),"B3按创建人查询可对接成果列表	-D3查询对接成果关系列表(公共)-是否存档不能为空",false);
Assert.isNull(queryAchievementDockingListComReqDto.getSpaceId(),"B3按创建人查询可对接成果列表	-D3查询对接成果关系列表(公共)-创建于空间ID不能为空",false);
      queryAchievementDockingListComRespDto = fwAppAchievementClient.queryAchievementDockingListCom(queryAchievementDockingListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;



//virtualUsage D2执行两数据集去除已存在(公共)  72177
      ImplementTwoDataRemovalExistsComRespDto implementTwoDataRemovalExistsComRespDto = null;
    if(batchQueryAchievementByCreateInductionIdComRespDto !=null&&queryAchievementDockingListComRespDto !=null){
          ImplementTwoDataRemovalExistsComReqDto implementTwoDataRemovalExistsComReqDto=new ImplementTwoDataRemovalExistsComReqDto();
  if(batchQueryAchievementByCreateInductionIdComRespDto!= null&&  batchQueryAchievementByCreateInductionIdComRespDto.getAchievementList() !=null&& !CollectionUtil.isEmpty(batchQueryAchievementByCreateInductionIdComRespDto.getAchievementList())){
      implementTwoDataRemovalExistsComReqDto.setDataSetsListOne(//objList-to-objLists
        batchQueryAchievementByCreateInductionIdComRespDto.getAchievementList().stream().map(item -> {
            com.wicket.okrcomponent.integration.dto.DataSetsListOneDto elm = new com.wicket.okrcomponent.integration.dto.DataSetsListOneDto();
      if(item!=null){
      elm.setCustomField(item.getAchievementId());//SimpleFieldAssign//sourceId:407557_2_72177
    }
        return elm;
      }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1970901_1_72177
    }
if(queryAchievementDockingListComRespDto!= null&&  queryAchievementDockingListComRespDto.getAchievementDockingList() !=null&& !CollectionUtil.isEmpty(queryAchievementDockingListComRespDto.getAchievementDockingList())){
      implementTwoDataRemovalExistsComReqDto.setDataSetsListTwo(//objList-to-objLists
        queryAchievementDockingListComRespDto.getAchievementDockingList().stream().map(item -> {
      DataSetsListTwoDto elm = new DataSetsListTwoDto();
      if(item!=null){
      elm.setCustomField(item.getAchievementId());//SimpleFieldAssign//sourceId:407562_2_72177
    }
        return elm;
      }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1970902_1_72177
    }

    /*D2执行两数据集去除已存在(公共)[5347]   */

      implementTwoDataRemovalExistsComRespDto = fwCompInterfaceModeClient.implementTwoDataRemovalExistsCom(implementTwoDataRemovalExistsComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;



           }
if((implementTwoDataRemovalExistsComRespDto!= null&&  implementTwoDataRemovalExistsComRespDto.getTwoDataRemovalExistsList() !=null && implementTwoDataRemovalExistsComRespDto.getTwoDataRemovalExistsList().size()>0)) {
        //if(D2将可对接的成果列表去除已经对接的成果列表.两数据集去除已存在列表数据集条数 大于 0)  72178

BatchQueryAchievementInfoComRespDto batchQueryAchievementInfoComRespDto = null;
    if(implementTwoDataRemovalExistsComRespDto !=null){
          BatchQueryAchievementInfoComReqDto batchQueryAchievementInfoComReqDto=new BatchQueryAchievementInfoComReqDto();
  batchQueryAchievementInfoComReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:1970921_1_72179
if(implementTwoDataRemovalExistsComRespDto!= null&&  implementTwoDataRemovalExistsComRespDto.getTwoDataRemovalExistsList() !=null&& !CollectionUtil.isEmpty(implementTwoDataRemovalExistsComRespDto.getTwoDataRemovalExistsList())){
      batchQueryAchievementInfoComReqDto.setAchievementList(implementTwoDataRemovalExistsComRespDto.getTwoDataRemovalExistsList().stream().map(item->item.getCustomField())
        .collect(Collectors.toList()));/*list-to-strings*///sourceId:1970920_1_72179
    }

    /*D3批量查询成果分页信息(公共)[9317]   */
    Assert.isNull(batchQueryAchievementInfoComReqDto.getSpaceId(),"B3按创建人查询可对接成果列表	-D3批量查询成果分页信息(公共)-创建于空间ID不能为空",false);
      batchQueryAchievementInfoComRespDto = fwAppAchievementClient.batchQueryAchievementInfoCom(batchQueryAchievementInfoComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


      batchQueryAchievementInfoComRespDto_1 = batchQueryAchievementInfoComRespDto;
           }
      }
BffBatchQueryAchievementDockByCreateInductionIdRespDto retData = new BffBatchQueryAchievementDockByCreateInductionIdRespDto();
  if(batchQueryAchievementInfoComRespDto_1!=null){
      retData.setAchievementDockingList(//objList-to-objLists
        batchQueryAchievementInfoComRespDto_1.getAchievementList().stream().map(item -> {
      BffAchievementDockingDto elm = new BffAchievementDockingDto();
      if(item!=null){
      elm.setAchievementId(item.getAchievementId());//SimpleFieldAssign//sourceId:407597_2
elm.setAchievementNumber(item.getAchievementNumber());//SimpleFieldAssign//sourceId:407598_2
elm.setAchievementName(item.getAchievementName());//SimpleFieldAssign//sourceId:407599_2
elm.setRelatedDocument(item.getRelatedDocument());//SimpleFieldAssign//sourceId:407600_2
elm.setAwardedUnit(item.getAwardedUnit());//SimpleFieldAssign//sourceId:407601_2
elm.setAwardedTime(item.getAwardedTime());//SimpleFieldAssign//sourceId:407602_2
elm.setValidEndTime(item.getValidEndTime());//SimpleFieldAssign//sourceId:407603_2
elm.setIsSymbolicAchievements(item.getIsSymbolicAchievements());//SimpleFieldAssign//sourceId:407604_2
elm.setAchievementTypeNumber(item.getAchievementTypeNumber());//SimpleFieldAssign//sourceId:407605_2
elm.setAchievementTypeName(item.getAchievementTypeName());//SimpleFieldAssign//sourceId:407606_2
elm.setAchievementCategoryNumber(item.getAchievementCategoryNumber());//SimpleFieldAssign//sourceId:407607_2
elm.setAchievementCategoryName(item.getAchievementCategoryName());//SimpleFieldAssign//sourceId:407608_2
elm.setAchievementGradeNumber(item.getAchievementGradeNumber());//SimpleFieldAssign//sourceId:407609_2
elm.setAchievementGradeName(item.getAchievementGradeName());//SimpleFieldAssign//sourceId:407610_2
elm.setAchievementBusinessGradeNumber(item.getAchievementBusinessGradeNumber());//SimpleFieldAssign//sourceId:407611_2
elm.setAchievementBusinessGradeName(item.getAchievementBusinessGradeName());//SimpleFieldAssign//sourceId:407612_2
elm.setCopyrightObjectId(item.getCopyrightObjectId());//SimpleFieldAssign//sourceId:407613_2
elm.setCopyrightObjectTypeCode(item.getCopyrightObjectTypeCode());//SimpleFieldAssign//sourceId:407614_2
elm.setCopyrightObjectName(item.getCopyrightObjectName());//SimpleFieldAssign//sourceId:407615_2
elm.setBelongName(item.getBelongName());//SimpleFieldAssign//sourceId:407616_2
elm.setDutyDeptId(item.getDutyDeptId());//SimpleFieldAssign//sourceId:407617_2
elm.setDutyDeptName(item.getDeptShortName());//SimpleFieldAssign//sourceId:407618_2
    }
        return elm;
      }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1970922_1
    }
  

  
  
return retData;
  }
  //
}
